Skip to content

Fix status item menu bar observation for token account snapshots (#2283) - #2511

Open
Yuxin-Qiao wants to merge 4 commits into
steipete:mainfrom
Yuxin-Qiao:fix/menu-bar-indicator-account-sync-2283
Open

Fix status item menu bar observation for token account snapshots (#2283)#2511
Yuxin-Qiao wants to merge 4 commits into
steipete:mainfrom
Yuxin-Qiao:fix/menu-bar-indicator-account-sync-2283

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

When account snapshots (accountSnapshots or codexAccountSnapshots) were updated, the status item menu bar observation token (iconObservationToken) in UsageStore was missing dependencies on these collections. This caused the status item menu bar icon to remain stale until another tracked property was invalidated.

Additionally, the work signature (accountSnapshotSignature) only tracked stable identity fields (id, label, email, isActive). When an existing snapshot's mutable state (usage percentages, errors, source labels) changed without the identity fields changing, the signature stayed the same and the status item icon was not refreshed.

Changes Made

  • Sources/CodexBar/UsageStore.swift: Add _ = self.accountSnapshots and _ = self.codexAccountSnapshots to iconObservationToken for observation invalidation.
  • Sources/CodexBar/StatusItemController+IconObservation.swift: Extend accountSnapshotSignature to include full mutable state per snapshot (primary/secondary/tertiary RateWindow details, error, sourceLabel) so icon redraws are triggered when usage data, errors, or source labels change.
  • Tests/CodexBarTests/StatusItemIconObservationSignatureTests.swift: Add focused invalidation unit tests:
    • accountSnapshots array mutation triggers observation invalidation.
    • codexAccountSnapshots array mutation triggers observation invalidation.
    • Replacing an existing account snapshot's usage (percent change) changes the signature.
    • Replacing an existing account snapshot's error changes the signature.
    • Replacing an existing codex account snapshot changes the signature.

Verification

  • Ran swift test --filter StatusItemIconObservationSignatureTests (25/25 passed).
  • Ran make check (0 format/lint violations).

Fixes #2283

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 1:22 AM ET / 05:22 UTC.

ClawSweeper review

What this changes

The PR makes token-account snapshot collections and their mutable usage, error, and source-label state participate in CodexBar’s menu-bar icon redraw observation, and adds focused regression tests.

Merge readiness

Blocked until real behavior proof from a real setup is added - 3 items remain

This remains a useful, focused fix for the stale menu-bar indicator path. The prior signature and observation findings appear addressed in the current PR head, but the PR still needs after-fix evidence from a freshly built CodexBar bundle showing an account-snapshot update actually redraws the menu-bar icon; reported tests and checks alone do not meet that merge gate.

Priority: P2
Reviewed head: 1abe620aecce2d15af3b131cde64f73958331e14

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and appears to resolve the earlier correctness gaps, but merge readiness is capped by missing real behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The contributor reports focused tests and make check, but the PR body and supplied discussion contain no after-fix run from a freshly built CodexBar bundle. Please add a redacted recording, terminal/live output, or runtime diagnostic showing the icon update; update the PR body afterward to trigger re-review, or ask a maintainer to comment @clawsweeper re-review if needed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The contributor reports focused tests and make check, but the PR body and supplied discussion contain no after-fix run from a freshly built CodexBar bundle. Please add a redacted recording, terminal/live output, or runtime diagnostic showing the icon update; update the PR body afterward to trigger re-review, or ask a maintainer to comment @clawsweeper re-review if needed.
Evidence reviewed 4 items PR implementation: The submitted diff adds both account-snapshot collections to the observation token and incorporates account and Codex snapshot mutable state into the controller’s icon work signature.
Regression coverage: The PR adds collection-observation and same-account mutable-state signature tests, addressing the two earlier review findings about signature gating and mutable snapshot values.
Review continuity: The latest contributor update states that primary, secondary, and tertiary rate-window values plus error and source label are now represented in the signature; this corresponds to the prior P1 review discussion that requested mutable-state coverage.
Findings None None.
Security None None.

How this fits together

Provider refreshes populate UsageStore with account-level usage snapshots. The status-item controller observes that store, compares a lightweight work signature, and redraws the macOS menu-bar icon only when the signature changes.

flowchart LR
    A[Provider usage refresh] --> B[Token account snapshots]
    B --> C[Usage store observation]
    C --> D[Icon work signature]
    D --> E[Status bar icon redraw]
    E --> F[Visible usage indicator]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The contributor reports focused tests and make check, but the PR body and supplied discussion contain no after-fix run from a freshly built CodexBar bundle. Please add a redacted recording, terminal/live output, or runtime diagnostic showing the icon update; update the PR body afterward to trigger re-review, or ask a maintainer to comment @clawsweeper re-review if needed.
  • Resolve merge risk (P1) - Without a real bundle-level demonstration, it remains unproven that the observation callback passes the controller’s signature gate and redraws the visible menu-bar item during an actual account-snapshot refresh.
  • Complete next step (P2) - The remaining blocker is contributor-supplied live runtime proof, which an automated repair lane cannot produce from the contributor’s setup.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Focused surface 3 files affected; 39 production lines and 182 test lines added The implementation stays within the usage store, icon observation gate, and dedicated regression coverage.
Prior blockers 2 earlier P1 findings addressed The latest head adds account-state signature input and tests for same-account mutable updates.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the focused observation and signature fix, then attach redacted runtime proof from a freshly built CodexBar bundle showing the menu-bar indicator changes after an account snapshot changes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the focused observation and signature fix, then attach redacted runtime proof from a freshly built CodexBar bundle showing the menu-bar indicator changes after an account snapshot changes.

Do we have a high-confidence way to reproduce the issue?

No high-confidence live reproduction was established in this read-only review. The source path and regression tests make the stale-signature mechanism reproducible from code, but not yet demonstrated in a freshly built running app.

Is this the best way to solve the issue?

Yes, with proof pending: observing the snapshot collections and including the mutable values that drive icon output is the narrowest maintainable fix for a redraw gate that previously ignored those changes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8ef86077e70a.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: This fixes a localized stale usage indicator that can mislead users but has no evidence of data loss, security impact, or process unavailability.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The contributor reports focused tests and make check, but the PR body and supplied discussion contain no after-fix run from a freshly built CodexBar bundle. Please add a redacted recording, terminal/live output, or runtime diagnostic showing the icon update; update the PR body afterward to trigger re-review, or ask a maintainer to comment @clawsweeper re-review if needed.

Evidence

What I checked:

  • PR implementation: The submitted diff adds both account-snapshot collections to the observation token and incorporates account and Codex snapshot mutable state into the controller’s icon work signature. (Sources/CodexBar/UsageStore.swift:56, 1abe620aecce)
  • Regression coverage: The PR adds collection-observation and same-account mutable-state signature tests, addressing the two earlier review findings about signature gating and mutable snapshot values. (Tests/CodexBarTests/StatusItemIconObservationSignatureTests.swift:294, 1abe620aecce)
  • Review continuity: The latest contributor update states that primary, secondary, and tertiary rate-window values plus error and source label are now represented in the signature; this corresponds to the prior P1 review discussion that requested mutable-state coverage. (Sources/CodexBar/StatusItemController+IconObservation.swift:64, 1abe620aecce)
  • Current PR state: The PR remains open and mergeable, with two macOS Swift-test shards still in progress; the GitHub context contains reported focused test and lint results but no recording, live output, or runtime diagnostic from an after-fix application run. (1abe620aecce)

Likely related people:

  • steipete: The repository is steipete/CodexBar; no readable local history was available in this review environment to establish a more specific current-main feature owner. (role: repository owner and likely decision owner; confidence: low; files: Sources/CodexBar/UsageStore.swift, Sources/CodexBar/StatusItemController+IconObservation.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach redacted after-fix evidence from a freshly built bundle that shows an account-snapshot refresh redraws the visible menu-bar icon.
  • Let the in-progress macOS Swift-test shards complete successfully before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-30T05:09:53.299Z sha a895280 :: needs real behavior proof before merge. :: [P2] Add observation invalidation regression coverage
  • reviewed 2026-07-30T14:25:51.099Z sha ce475ec :: needs real behavior proof before merge. :: [P1] Feed account snapshots into the icon work signature
  • reviewed 2026-07-30T15:03:33.437Z sha 0b7e280 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T15:27:47.903Z sha 0b7e280 :: needs real behavior proof before merge. :: [P1] Include mutable snapshot state in the work signature
  • reviewed 2026-07-31T04:35:06.769Z sha 1abe620 :: needs real behavior proof before merge. :: none

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce475ecc1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +59 to +60
_ = self.accountSnapshots
_ = self.codexAccountSnapshots

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Feed account snapshots into the icon work signature

Once the initial icon signature is stored, a refresh that changes only either per-account collection triggers this observation but still does no icon work: observeStoreIconChanges() recomputes storeIconObservationSignature() and returns because that signature reads store.snapshot(for:) and never accountSnapshots or codexAccountSnapshots. The status indicator therefore remains stale in the scenario these dependencies are intended to fix; include the relevant account state in the signature/render source (or publish it into snapshots) and test through the controller's signature gate rather than only asserting raw Observation invalidation.

AGENTS.md reference: AGENTS.md:L4-L5

Useful? React with 👍 / 👎.

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b7e280360

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +73 to +75
let accountPart = accountSnapshots.map { snap in
let label = snap.account.label
return "\(snap.account.id.uuidString):\(label)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include mutable account state in the signature

The new signature projection is fresh evidence that the previously reported gate remains incomplete: an ordinary refresh replaces an existing TokenAccountUsageSnapshot with updated snapshot, error, or sourceLabel values while preserving its ID and label, so Observation fires but this string remains unchanged and observeStoreIconChanges() returns without updating the status item. The Codex projection has the same problem because it retains only ID, email, and active state; include the mutable fields that are intended to trigger icon work and cover a same-account refresh rather than only insertion into an empty collection.

Useful? React with 👍 / 👎.

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Here is the technical summary and evidence for PR #2511:

Problem & Fix Summary

  • Observation Token Registration: In Sources/CodexBar/UsageStore.swift, iconObservationToken accesses accountSnapshots and codexAccountSnapshots so changes in account snapshots trigger observation update cycles.
  • Icon Observation Signature Invalidation: In Sources/CodexBar/StatusItemController+IconObservation.swift, providerStoreIconObservationSignature now includes accountSnapshotSignature(for: provider). This ensures that when accountSnapshots or codexAccountSnapshots mutate, the computed icon observation signature changes, invalidating stale menu bar icon renders and forcing an immediate icon redraw.

Test Coverage & Evidence

  • Added unit tests in Tests/CodexBarTests/StatusItemIconObservationSignatureTests.swift:
    1. test_statusItemIconObservationSignature_changesWhenAccountSnapshotsMutate(): Verifies signature changes when mutating accountSnapshots[.codex].
    2. test_statusItemIconObservationSignature_changesWhenCodexAccountSnapshotsMutate(): Verifies signature changes when mutating codexAccountSnapshots.
  • All tests pass 100% locally. make check confirms 0 SwiftFormat and 0 SwiftLint violations across 1,658 files.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Jul 30, 2026
…teipete#2511)

The accountSnapshotSignature only tracked stable identity fields, so
replacing an account snapshot's usage, error, or source label did not
invalidate the observation token. Extend the signature to include the
full snapshot state (primary/secondary/tertiary RateWindow details,
error, sourceLabel) so icon redraws are triggered when mutable data
changes.

Add regression tests for:
- Account snapshot usage replacement
- Account snapshot error replacement
- Codex account snapshot replacement

Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper The mutable snapshot state has been added to the work signature. Specifically:

  • now includes primary/secondary/tertiary RateWindow details (usedPercent, windowMinutes, resetsAt), error, and sourceLabel for each snapshot entry
  • Added regression tests for usage replacement, error replacement, and codex account snapshot replacement scenarios

Please re-review.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu bar usage indicator is stale and does not match the opened menu

1 participant